home *** CD-ROM | disk | FTP | other *** search
- '=================================================================
- ' PROGRAM: CUBIC.BAS
- ' AUTHOR: Rob McGregor
- '-----------------------------------------------------------------
- ' PURPOSE: Creates a Polyray scene file containing 3 spheres
- ' that follow different cubic paths, starting and
- ' ending at the same points. The paths are controlled
- ' by the variables s1Nc, s2Nc, and s3Nc (the Nc
- ' parameter in the equations)
- '-----------------------------------------------------------------
- ' This is a "virtual animation," in that it calculates
- ' the positions of the 3 spheres for each virtual frame,
- ' and adjusts the transparency of the spheres based on
- ' the value of t. The resulting image shows the entire
- ' animation in only 1 frame.
- '=================================================================
-
- DECLARE SUB cubic (s1Nc!, s2Nc!, s3Nc!, s1Nd!, s2Nd!, s3Nd!, startF%, endF%, fout$)
-
- CLS
- PRINT "This program creates a Polyray scene file demonstrating ";
- PRINT "cubic blending."
- PRINT
- PRINT "Please enter a path and file name for the resulting ";
- PRINT "Polyray scene file"
- LINE INPUT "==>"; fout$
-
- INPUT "Slope Nc of sphere 1 (from -10 to 10)"; s1Nc!
- INPUT "Slope Nc of sphere 2 (from -10 to 10)"; s2Nc!
- INPUT "Slope Nc of sphere 3 (from -10 to 10)"; s3Nc!
-
- INPUT "Slope Nd of sphere 1 (from -10 to 10)"; s1Nd!
- INPUT "Slope Nd of sphere 2 (from -10 to 10)"; s2Nd!
- INPUT "Slope Nd of sphere 3 (from -10 to 10)"; s3Nd!
-
- INPUT "Starting frame of the virtual animation"; startF%
- INPUT "Ending frame of the virtual animation"; endF%
-
- CALL cubic(s1Nc!, s2Nc!, s3Nc!, s1Nd!, s2Nd!, s3Nd!, startF%, endF%, fout$)
- PRINT : PRINT "Done!": PRINT
-
- SUB cubic (s1Nc!, s2Nc!, s3Nc!, s1Nd!, s2Nd!, s3Nd!, startF%, endF%, fout$)
-
- OPEN fout$ FOR OUTPUT AS #1
-
- ' Declare variables
- DIM frame%, t, i, format$
- DIM N3x!, N3y!, temp$, tex!
- DIM s1x!, s1y!, s2x!, s2y!, s3x!, s3y!
- DIM s1N1x!, s1N1y!, s1N2x!, s1N2y!
- DIM s2N1x!, s2N1y!, s2N2x!, s2N2y!
- DIM s3N1x!, s3N1y!, s3N2x!, s3N2y!
-
- ' Write the file
- PRINT #1, "// Scene File: CUBE.PI"
- PRINT #1, "// Author: Rob McGregor"
- PRINT #1, ""
- PRINT #1, "/***************************************************"
- PRINT #1, " Virtual animation of 3 spheres following different"
- PRINT #1, " cubic paths, each starting and ending at the same"
- PRINT #1, " relative points on the y-axis."
- PRINT #1, "****************************************************/"
- PRINT #1, ""
- PRINT #1, "// SET UP THE CAMERA"
- PRINT #1, "viewpoint {"
- PRINT #1, " from <4.5, 0, -11.5>"
- PRINT #1, " at <4.5, 1, 0>"
- PRINT #1, " up <0, 1, 0>"
- PRINT #1, " angle 45"
- PRINT #1, " resolution 320, 240"
- PRINT #1, " aspect 4/3"
- PRINT #1, "}"
- PRINT #1, ""
- PRINT #1, "background Grey"
- PRINT #1, ""
- PRINT #1, "// Lights"
- PRINT #1, "light <-5, 5, -20>"
- PRINT #1, "light <5, 5, -20>"
- PRINT #1, ""
-
- PRINT #1, "define s1color"
- PRINT #1, "surface { "
- PRINT #1, " color red"
- PRINT #1, " ambient 0.1"
- PRINT #1, " diffuse 0.2"
- PRINT #1, " specular 0.8"
- PRINT #1, " microfacet Cook 0.2"
- PRINT #1, " reflection 0.3 "
- PRINT #1, "}"
- PRINT #1, ""
-
- PRINT #1, "define s2color"
- PRINT #1, "surface { "
- PRINT #1, " color yellow"
- PRINT #1, " ambient 0.1"
- PRINT #1, " diffuse 0.2"
- PRINT #1, " specular 0.8"
- PRINT #1, " microfacet Cook 0.2"
- PRINT #1, " reflection 0.3 "
- PRINT #1, "}"
- PRINT #1, ""
-
- PRINT #1, "define s3color"
- PRINT #1, "surface { "
- PRINT #1, " color blue"
- PRINT #1, " ambient 0.1"
- PRINT #1, " diffuse 0.2"
- PRINT #1, " specular 0.8"
- PRINT #1, " microfacet Cook 0.2"
- PRINT #1, " reflection 0.3 "
- PRINT #1, "}"
- PRINT #1, ""
-
- FOR i% = startF% TO endF%
-
- ' compute t
- frame% = i%
- t = (frame% - startF%) / (endF% - startF%)
-
- ' set the parameters of the equation
- s1N1x! = 0 ' x-axis starting point
- s1N1y! = -1 ' y-axis starting point
- s1N2x! = 9 ' x-axis ending point
- s1N2y! = -1 ' y-axis ending point
-
- s2N1x! = 0 ' x-axis starting point
- s2N1y! = 0 ' y-axis starting point
- s2N2x! = 9 ' x-axis ending point
- s2N2y! = 0 ' y-axis ending point
-
- s3N1x! = 0 ' x-axis starting point
- s3N1y! = 1 ' y-axis starting point
- s3N2x! = 9 ' x-axis ending point
- s3N2y! = 1 ' y-axis ending point
-
- ' Now calculate the locations of the spheres using:
- ' N = (1 - t)^3 * N1 + (t^3) * N2 + 3 * t *
- ' ((1 - t)^2) * Nc + 3 * (t^2) * (1 - t) * Nd
-
- ' use variables to calculate only once
- t2 = t ^ 2
- t3 = t ^ 3
- lessT3 = (1 - t) ^ 3
- lessT2 = (1 - t) ^ 2
-
- s1x! = lessT3 * s1N1x! + t3 * s1N2x! + 3 * t * lessT2 * s1Nc! + 3 * t2 * (1 - t) * s1Nd!
- s1y! = lessT3 * s1N1y! + t3 * s1N2y! + 3 * t * lessT2 * s1Nc! + 3 * t2 * (1 - t) * s1Nd!
- s2x! = lessT3 * s2N1x! + t3 * s2N2x! + 3 * t * lessT2 * s2Nc! + 3 * t2 * (1 - t) * s2Nd!
- s2y! = lessT3 * s2N1y! + t3 * s2N2y! + 3 * t * lessT2 * s2Nc! + 3 * t2 * (1 - t) * s2Nd!
- s3x! = lessT3 * s3N1x! + t3 * s3N2x! + 3 * t * lessT2 * s3Nc! + 3 * t2 * (1 - t) * s3Nd!
- s3y! = lessT3 * s3N1y! + t3 * s3N2y! + 3 * t * lessT2 * s3Nc! + 3 * t2 * (1 - t) * s3Nd!
-
- ' calc the transparency of the spheres
- tex! = (1 - t) * .9 + t * .4
- format$ = "###.###"
-
- line$ = "define s1tex" + LTRIM$(STR$(frame%))
- line$ = line$ + " texture { s1color { transmission white,"
- PRINT #1, line$;
- PRINT #1, USING format$; tex!;
- PRINT #1, ", 1 }}"
-
- line$ = "define s2tex" + LTRIM$(STR$(frame%))
- line$ = line$ + " texture { s2color { transmission white,"
- PRINT #1, line$;
- PRINT #1, USING format$; tex!;
- PRINT #1, ", 1 }}"
-
- line$ = "define s3tex" + LTRIM$(STR$(frame%))
- line$ = line$ + " texture { s3color { transmission white,"
- PRINT #1, line$;
- PRINT #1, USING format$; tex!;
- PRINT #1, ", 1 }}"
-
- PRINT #1, "object { sphere <";
- PRINT #1, USING format$; s1x!;
- PRINT #1, ",";
- PRINT #1, USING format$; s1y!;
- PRINT #1, ", 0>, 0.5";
- line$ = " s1tex" + LTRIM$(STR$(frame%)) + " }"
- PRINT #1, line$
-
- PRINT #1, "object { sphere <";
- PRINT #1, USING format$; s2x!;
- PRINT #1, ",";
- PRINT #1, USING format$; s2y!;
- PRINT #1, ", 0>, 0.5";
- line$ = " s2tex" + LTRIM$(STR$(frame%)) + " }"
- PRINT #1, line$
-
- PRINT #1, "object { sphere <";
- PRINT #1, USING format$; s3x!;
- PRINT #1, ",";
- PRINT #1, USING format$; s3y!;
- PRINT #1, ", 0>, 0.5";
- line$ = " s3tex" + LTRIM$(STR$(frame%)) + " }"
- PRINT #1, line$
- PRINT #1, ""
-
- NEXT i%
- CLOSE #1
-
- END SUB
-
-